require(['./config'],()=>{
    require(['jquery','cookie'],()=>{
        class Login{
            constructor(){
                this.init()
            }
        init(){
             $('#oklogin').on('click',function(){
                  const name=$('#nameInput').val(),
                   pwd=$('#pwdInput').val()
                   let userList = localStorage.getItem('userList')
                   if(userList){
                        userList=JSON.parse(userList)
                        let is =userList.some((user)=>{
                            return user.name === name && user.pwd === pwd
                        })
                        if(is){
                            $.cookie('username',name,{path:'/'})
                            alert('登陆成功，前往首页')
                            window.open('/index.html','_self')
                        
                        }else{
                            alert('用户名或密码错误，重新输入')
                        }
                   }else{
                        alert('还没有用户，先去注册')
                        location.replace('/html/register.html')
                 }
             })
                  
            }    
            
        }
        new Login()
    })
})